//package com.campusnews.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
//import com.campusnews.mapper.FirstCommentMapper;
//import com.campusnews.mapper.SecondCommentMapper;
//import com.campusnews.pojo.CommentAgree;
//import com.campusnews.mapper.CommentAgreeMapper;
//import com.campusnews.pojo.FirstComment;
//import com.campusnews.pojo.SecondComment;
//import com.campusnews.service.CommentAgreeService;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.campusnews.utils.JsonResult;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
///**
// * <p>
// *  服务实现类
// * </p>
// *
// * @author lqc
// * @since 2021-10-14
// */
//@Service
//public class CommentAgreeServiceImpl extends ServiceImpl<CommentAgreeMapper, CommentAgree> implements CommentAgreeService {
//
//    @Autowired
//    private CommentAgreeMapper commentAgreeMapper;
//
//    @Autowired
//    private FirstCommentMapper firstCommentMapper;
//
//    @Autowired
//    private SecondCommentMapper secondCommentMapper;
//
//    @Override
//    public JsonResult deleteCommentAgreeFromFirstComment(int firstId, int userId) {
//        FirstComment firstComment = firstCommentMapper.selectById(firstId);
//        if (firstComment.getAgreeNum()>0){
//            firstComment.setAgreeNum(firstComment.getAgreeNum()-1);
//        }
//        UpdateWrapper<FirstComment> wrapper1 = new UpdateWrapper<>();
//        wrapper1.eq("user_id",userId)
//                .eq("first_id",firstId);
//        firstCommentMapper.update(firstComment,wrapper1);
//        QueryWrapper<CommentAgree> wrapper = new QueryWrapper<>();
//        wrapper.eq("user_id",userId)
//                .eq("first_id",firstId);
//        int delete = commentAgreeMapper.delete(wrapper);
//        if (delete==1){
//            return JsonResult.build(200,"取消点赞",delete);
//        }else {
//            return JsonResult.errorMsg("取消失败");
//        }
//    }
//
//    @Override
//    public JsonResult deleteCommentAgreeFromSecondComment(int secondId,int userId) {
//        SecondComment secondComment = secondCommentMapper.selectById(secondId);
//        if (secondComment.getAgreeNum()>0){
//            secondComment.setAgreeNum(secondComment.getAgreeNum()-1);
//        }
//        secondCommentMapper.updateById(secondComment);
//        UpdateWrapper<SecondComment> wrapper1 = new UpdateWrapper<>();
//        wrapper1.eq("user_id",userId)
//                .eq("second_id",secondId);
//        secondCommentMapper.update(secondComment,wrapper1);
//        QueryWrapper<CommentAgree> wrapper = new QueryWrapper<>();
//        wrapper.eq("user_id",userId)
//                .eq("second_id",secondId);
//        int delete = commentAgreeMapper.delete(wrapper);
//        if (delete==1){
//            return JsonResult.build(200,"取消点赞",delete);
//        }else {
//            return JsonResult.errorMsg("取消失败");
//        }
//    }
//
//    @Override
//    public JsonResult insertCommentAgree(CommentAgree commentAgree) {
//        if (commentAgree.getFirstId()!=0){
//            QueryWrapper<FirstComment> wrapper = new QueryWrapper<>();
//            wrapper.eq("first_id",commentAgree.getFirstId())
//                    .eq("user_id",commentAgree.getUserId());
//            FirstComment firstComment = firstCommentMapper.selectOne(wrapper);
//            firstComment.setAgreeNum(firstComment.getAgreeNum()+1);
//            firstCommentMapper.updateById(firstComment);
//            commentAgreeMapper.insert(commentAgree);
//            return JsonResult.build(200,"一级评论点赞成功",null);
//        }else if (commentAgree.getSecondId()!=0){
//            QueryWrapper<SecondComment> wrapper = new QueryWrapper<>();
//            wrapper.eq("second_id",commentAgree.getSecondId())
//                    .eq("user_id",commentAgree.getUserId());
//            SecondComment secondComment = secondCommentMapper.selectOne(wrapper);
//            secondComment.setAgreeNum(secondComment.getAgreeNum()+1);
//            secondCommentMapper.updateById(secondComment);
//            commentAgreeMapper.insert(commentAgree);
//        }else {
//            return JsonResult.errorMsg("点赞异常");
//        }
//        return null;
//    }
//}
